$(function () {
    $("#login").click(function () {
        var username = $("#username").val();//取值
        var password = $("#password").val();
        if (!username) {
            alert("用户名必填!");
            $("#username").focus();//获取焦点
            return;
        }
        if (!password) {
            alert("密码必填!");
            $("#password").focus();//获取焦点
            return;
        }

        $.ajax({
            url: "/user/login", //数据库地址
            type: "get",
            data: {
                "username": username,
                "password": password
            },
            // beforeSend: function (xhr) {
            //     console.log("before send");
            // },
            success: function (data) {
                if (data == true) {
                    alert("登录成功！");
                    location.href = "../page/index.html";
                }
                else
                    alert("Error!");
            },
            error: function () {
                console.log("请求error");
            }
            // complete: function (xhr) {
            //     console.log("complete");
            //     console.log(xhr);
            // }
        })
    });
})
